<extend name="Public/common" />
<block name="body">
	<input type="hidden" id="goodsId" value="" />
	<input type="hidden" id="storeId" value="" />
	<input type="hidden" id="regionId" value="{$region_id}" />
	<input type="hidden" id="sellTime" value="" />
	<div class="mywp">

		<div class="af-inp">
			<p>{$region_name}</p><span></span>
		</div>
		<div class="ahided animated">
			<div class="ahide-d">
				<div class="tips"></div>
				<p class="txt">你可以在这里输入您所在的楼宇</p>
				<span class="btn" onclick="$('.ahided').addClass('fadeInDown').addClass('fadeOutUp');">我知道了</span>
			</div>
		</div>

		<div class="ahide animated">
			<div class="ahide-c">
				<div class="ahide-title clearfix bg-b">
					<p class="tit-l l"><img src="__IMG__/icob.png"/><input style="color:#fff;" id="building" type="text" value="" placeholder="请输入楼宇名称" /></p>
					<p class="tit-r r"><img src="__IMG__/ico8-1.png"/><span class="ai">|</span><span class="quxiao">取消</span></p>
				</div>
				<p class="aprompt">选择您所在楼宇</p>
				<ul class="ahide-wrap">
					<li class="bg"><p>国家软件大厦</p></li>
					<li><p>国家软件大厦1</p></li>
					<li><p>国家软件大厦2</p></li>
					<li><p>国家软件大厦3</p></li>
					<li><p>国家软件大厦4</p></li>
					<li><p>国家软件大厦5</p></li>
					<li><p>国家软件大厦6</p></li>
					<li><p>国家软件大厦7</p></li>
				</ul>
			</div>
		</div>
		<div class="atop">
			<div class="atop-t clearfix">
				<img src="__IMG__/pic1.png"/>
				<div class="atop-kong">
					<div class="alt">
						<div class="clearfix"><span class="lm"><img src="__IMG__/bopacity.png" /></span><span class="rm">售罄</span></div>
					</div>
				</div>
			</div>
			<div class="atop-b clearfix">
				<div class="atop-l l">
					<p><img src="__IMG__/clock.png"/>&nbsp; 距离结束</p>
					<div class="as-time">
						<span class="ah">00</span> : <span class="am">00</span> : <span class="as">00</span>
					</div>
				</div>
				<div class="atop-r r bg-b">
					<span>特卖剩余</span><span class="col-y qing">0</span><span>份</span>
				</div>
			</div>
		</div>
		<div class="aproduct-info">
			<h2>BuyTime熊菓冰淇淋蛋糕</h2>
			<p>会&nbsp; 员&nbsp; 价:<span class="col-r" id="jiageVip">0</span><em>元</em></p>
			<p>抢&nbsp; 购&nbsp; 价:<span class="col-r" id="qiangv">0</span><em>元</em></p>
			<p class="adel">堂食售价:<span id="tangshi">0</span><em>元</em></p>
			<p class="col-b clearfix"><img src="__IMG__/b.png"/><em><span>0</span>月<span>0</span>日 <span>00:00</span> 送达</em></p>
			<div class="asmile"><img src="__IMG__/xiajian.png"/></div>
		</div>
		<div class="adetails animated">
			<p class="adetails-t bg-b">详情</p>
			<div class="adetails-c" id="restaurantDetails">
			</div>
		</div>
		<p class="abotto">到底了哦～</p>
		<div class="order-form-footer-btn mbto clots">
			<img src="__IMG__/buytimebtn.png" />
			<div><span class="fl col-y">遇到问题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联系我们</span> <img src="__IMG__/youjian.png"/></div>
		</div>
		<div class="abtn">
			<a href="{:C('SITE_URL')}wechat/index/orderInfo/">订购午餐</a>
			<span>订购午餐</span>
		</div>
	</div>
</block>
<block name="js">
	<script src="__WECHAT__/js/main.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var timer;
		//点击楼宇
		function clickBlid(){
			touch.on($('.ahide-wrap li p'), 'touchstart', function(ev){
				$('.ahide-wrap li').removeClass('bg');
				$(this).parent().addClass('bg');
			});
			$('.ahide-wrap li p').each(function(i,e){
				$(e).click(function(){
					$('.af-inp p').text($(e).text());
					$('.ahide').removeClass('fadeInDown');
					$('.ahide').addClass("fadeOutUp");
					setTimeout(function () {
						$('.ahide').hide();
					},500);
					//添加页面信息
					htmlDetail($(e).parent().attr('sid'));
				});
			});
		}

		//时间转化
		function add0(m){return m<10?'0'+m:m }
		function format(shijianchuo,time_type){
			var time = new Date(shijianchuo * 1000);
			var m = time.getMonth()+1;
			var d = time.getDate();
			var h = time.getHours();
			var mm = time.getMinutes();
			if (time_type == "1"){
				return  add0(m)+'月'+add0(d)+'日 '+add0(h)+':'+add0(mm);
			} else {
				return  add0(h)+':'+add0(mm);
			}
		}

		//点击楼宇之后给页面添加详细信息
		function htmlDetail(id){

			$.get('{:C("SITE_URL")}wechat/index/getAreaGoodss?region_id='+id,function(data){
				//根据id获取楼宇信息，然后设置整个页面的详情
				if(data.code == '0'){
					var datas = data.data;
					$('#goodsId').val(datas.goods_id);//商品ID
					$('#storeId').val(datas.store_id);//店铺ID
					$('.aproduct-info').find('h2').text(datas.goods_name);//名称
					$('.atop-t').find('img').eq(0).attr('src',datas.goods_image);//图片
					$('#jiageVip').text(datas.member_price); //会员价格
					$('#qiangv').text(datas.shop_price); //抢购价格
					$('#tangshi').text(datas.market_price);//堂食价格
					$('.qing').text(datas.goods_storage);//特卖剩余
					$('#sellTime').val(datas.end_sell_time);

					if(datas.goods_storage<=0){
						$('.atop-kong').show();
						var aBox = $('.abtn').find('a');
						var spanBox = $('.abtn').find('span');
						var Hei = 0;
						spanBox.css({'display':'block','line-height':Hei+"px"});
						aBox.hide();
					}else{
						$('.atop-kong').hide();

						var aBox = $('.abtn').find('a');
						var spanBox = $('.abtn').find('span');
						var Hei = 0;
						aBox.css({'display':'block','line-height':Hei+"px"});
						spanBox.hide();
					}
					$('#restaurantDetails').html(datas.goods_content);//餐厅详情
					clearInterval(timer);
					$('.as').text('');
					$('.am').text('');
					$('.ah').text('');
					countdown();
					if(datas.deliver == ""){
						$('.col-b').find('em').html(format(datas.start_deliver_time, "1") + ' - ' + format(datas.end_deliver_time)+' 送达');
					} else {
						$('.col-b').find('em').html(format(datas.start_deliver_time, "1") + ' - ' + format(datas.end_deliver_time)+' 送达(<span style="color:#ff0024">' + datas.deliver+'</span>)');

					}
				} else if(data.code == '3') {
					var datas = data.data;
					$('#goodsId').val(datas.goods_id);//商品ID
					$('#storeId').val(datas.store_id);//店铺ID
					$('.aproduct-info').find('h2').text(datas.goods_name);//名称
					$('.atop-t').find('img').eq(0).attr('src',datas.goods_image);//图片
					$('#jiageVip').text(datas.member_price); //会员价格
					$('#qiangv').text(datas.shop_price); //抢购价格
					$('#tangshi').text(datas.market_price);//堂食价格
					$('.qing').text(datas.goods_storage);//特卖剩余
					$('#sellTime').val(datas.end_sell_time);

					var aBox = $('.abtn').find('a');
					var spanBox = $('.abtn').find('span');
					var Hei = aBox.height()>0?aBox.height():spanBox.height();
					spanBox.css({'display':'block','line-height':Hei+"px"});
					spanBox.attr("class", "agray");
					spanBox.text("每次只能购买一份");
					aBox.hide();

					if(datas.goods_storage<=0){
						$('.atop-kong').show();
						spanBox.text("售罄");
					}else{
						$('.atop-kong').hide();
					}

					$('#restaurantDetails').html(datas.goods_content);//餐厅详情
					clearInterval(timer);
					$('.as').text('');
					$('.am').text('');
					$('.ah').text('');
					countdown();

					$('.col-b').find('em').html(format(datas.start_deliver_time, "1") + ' - ' + format(datas.end_deliver_time)+' 送达');
				} else {
					$('#goodsId').val('0');//商品ID
					$('#storeId').val('0');//店铺ID
					$('.aproduct-info').find('h2').text('');//名称
					$('.atop-t').find('img').eq(0).attr('src','/wechat/images/pic1.png');//图片
					$('#jiageVip').text('0'); //会员价格
					$('#qiangv').text('0'); //抢购价格
					$('#tangshi').text('0');//堂食价格
					$('.qing').text('0');//特卖剩余
					$('#sellTime').val('0');
					$('.atop-kong').show();
					var aBox = $('.abtn').find('a');
					var spanBox = $('.abtn').find('span');
					var Hei = aBox.height()>0?aBox.height():spanBox.height();
					spanBox.css({'display':'block','line-height':Hei+"px"});
					aBox.hide();
					$('#restaurantDetails').html('');//餐厅详情
					clearInterval(timer);
					$('.as').text('00');
					$('.am').text('00');
					$('.ah').text('00');
					$('.col-b').find('em').html('00月00日 00:00 - 00:00 送达');
					salert(data.msg);
				}
			});
		}

		//获取楼层
		function getLou(){
			$.get('{:C("SITE_URL")}wechat/index/getRegionList',function(data){
				if(data.code == '0'){
					var html = '';
					var arr = data.data.list;
					for(var i=0;i<arr.length;i++){
						html+='<li sid="'+arr[i].region_id+'"><p>'+arr[i].region_name+'</p></li>';
					}
					$('.ahide-wrap').html(html);

					if(data.data.first==0){
						$('.ahide').removeClass('fadeOutUp');
						$('.ahide').addClass("fadeInDown");
						$('.ahide').show();
						$('.tips-wp').show();
						$('#building').val('');
					}
					//点击楼宇
					clickBlid();
				}
			});
		}
		getLou();

		//设置订购午餐
		var aBox = $('.abtn').find('a');
		var spanBox = $('.abtn').find('span');
		aBox.css({'line-height':aBox.height()+"px"});
		spanBox.css({'line-height':spanBox.height()+"px"});

		//售罄
		function sellAll(){
			//显示售罄
			if (parseInt($('.qing').text()) <= 0) {
				$('.atop-kong').show();
				setTimeout(function(){ $('.rm').css({'height':$('.lm').height()-8,'font-size':$('.lm').height()-8,'line-height':($('.lm').height()-8)+'px'});},250);

				var aBox = $('.abtn').find('a');
				var spanBox = $('.abtn').find('span');
				var Hei = aBox.height()>0?aBox.height():spanBox.height();
				spanBox.css({'display':'block','line-height':Hei+"px"});
				aBox.hide();
			}
		}

		function countdown(){
			var nowTime = new Date().getTime();
			var endTime = new Date($('#sellTime').val() * 1000);
			var t = endTime.getTime() - nowTime;
			if(t <= 0){
				$('.as').text('');
				$('.am').text('');
				$('.ah').text('');
				sellAll();
				return false;
			}
			var d = Math.floor(t/1000/60/60/24) * 24;
			var h = Math.floor(t/1000/60/60%24);
			var i = Math.floor(t/1000/60%60);
			var s = Math.floor(t/1000%60);

			$('.as').text(s);
			$('.am').text(i);
			$('.ah').text(h+d);
			setTimeout(countdown, 1000);
		}

		//显示售罄
		sellAll();

		//点击输入框
		//touch.on($('.af-inp'), 'touchend', function(){
		$('.af-inp').click(function(){
			$('.ahide').removeClass('fadeOutUp');
			$('.ahide').addClass("fadeInDown");
			$('.ahide').show();
			$('#building').val('');
		});

		//点击取消
		touch.on($('.tit-r').find('.quxiao'), 'touchend', function(ev){
			$('.ahide').removeClass('fadeInDown');
			$('.ahide').addClass("fadeOutUp");
			$('#building').val('');
			setTimeout(function () {
				$('.ahide').hide();
			},500);
		});

		//点击清空输入框
		$('.tit-r').find('img').click(function(){
			$('#building').val('');
			getLou();
		});
		$('#building').on('input',function(){
			//获取楼层
			$.get('{:C("SITE_URL")}wechat/index/getRegionList?keyword='+$('#building').val(),function(data){
				if(data.code == '0'){
					var html = '';
					var arr = data.data.list;
					for(var i=0;i<arr.length;i++){
						html+='<li sid="'+arr[i].region_id+'"><p>'+arr[i].region_name+'</p></li>';
					}
					$('.ahide-wrap').html(html);
					//点击楼宇
					clickBlid();
					//添加页面信息
//					htmlDetail($(e).parent().attr('sid'));
				}
			});
		});

		var headImg = $(".atop-t").find("img").eq(0);
		headImg.height((420/680)*headImg.width());

		$(document).ready(function() {
			htmlDetail($('#regionId').val());
		});
	</script>
</block>